package com.jiangxiaofei.citycloud.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.bean.BaiduPlaceBean;

import java.util.List;

/**
 * 作者: JiangXfei
 * 日期: 2017/9/20 0020
 */

public class CarResultAdapter extends BaseAdapter {
    Context mContext;
    List<BaiduPlaceBean.ResultsBean> placeList;

    public CarResultAdapter(Context mContext, List<BaiduPlaceBean.ResultsBean> poiInfoList) {
        this.mContext = mContext;
        this.placeList = poiInfoList;
    }

    @Override
    public int getCount() {
        return placeList.size();
    }

    @Override
    public Object getItem(int i) {
        return placeList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_car_map_search_result_layout, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_search.setText(placeList.get(i).getName());
        return view;
    }

    private class ViewHolder {
        TextView tv_search;

        public ViewHolder(View v) {
            this.tv_search = v.findViewById(R.id.tv_items_car_map_search_result);
        }
    }
}
